﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;

namespace Perovich.GameObjects.Tools.Util
{
    public class AutoFunction
    {
        private CodeMemberMethod meth;

        public CodeMemberMethod Meth
        {
            get
            {
                if (!string.IsNullOrEmpty(Summary)) meth.Comments.Add(new CodeCommentStatement("<summary>" + Summary + "</summary>", true));
                if (Param != null)
                    for (int i = 0; i < meth.Parameters.Count; i++ )
                    {
                        if (!string.IsNullOrEmpty(Param[i])) meth.Comments.Add(new CodeCommentStatement("<param name=\"" + meth.Parameters[i].Name + "\">" + Param[i] + "</param>", true));
                    }
                if (!string.IsNullOrEmpty(Returns)) meth.Comments.Add(new CodeCommentStatement("<returns>" + Returns + "</returns>", true));
                return meth;
            }
        }

        private string summary;

        public string Summary
        {
            get { return summary; }
            set { summary = value; }
        }
        private string returns;

        public string Returns
        {
            get { return returns; }
            set { returns = value; }
        }
        private string[] param;

        public string[] Param
        {
            get { return param; }
            set { param = value; }
        }

        public AutoFunction(string name, string returnType, CodeParameterDeclarationExpression[] args, MemberAttributes attri = MemberAttributes.Public | MemberAttributes.Final)
        {
            this.meth = new CodeMemberMethod();
            meth.Attributes = attri;
            meth.ReturnType = new CodeTypeReference(returnType);
            meth.Name = name;
            meth.Parameters.AddRange(args);
        }

        public AutoFunction(string name, Type returnType, CodeParameterDeclarationExpression[] args, MemberAttributes attri = MemberAttributes.Public | MemberAttributes.Final)
        {
            this.meth = new CodeMemberMethod();
            meth.Attributes = attri;
            meth.ReturnType = new CodeTypeReference(returnType);
            meth.Name = name;
            meth.Parameters.AddRange(args);
        }

        public void AddLine(CodeStatement line)
        {
            this.meth.Statements.Add(line);
        }

    }
}
